home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Precision Software Appli…tions Silver Collection 4
/
Precision Software Applications Silver Collection Volume 4 (1993).iso
/
stats
/
chadyn.exe
/
YXCROSS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-12-08
|
5KB
|
157 lines
/* YXCROSS.C - X windows routines for handling crosses.
* Written by Eric Kostelich, Institute for Physical Science and Technology,
* University of Maryland, College Park, MD 20742.
* Copyright (c) 1988 by James A. Yorke.
*/
#define XINCLUDES
#include "yinclud.h"
#ifdef X11
typedef struct {
int width, height; /* total size in pixels of cross */
Pixmap contents; /* of region before cross was drawn */
POINT origin; /* of upper left hand corner of
* saved contents rectangle */
} CROSSINFO;
extern POINT *FindPixel();
static CROSSINFO scrncross[2];
/* ------------------------------------------------------------------- */
/* CROSS - Place a cross at (x, y) containing W pixels on either side of
* X and H pixels on either side of Y. If PICNUM is equal to
* SCRN, then the cross is placed on the screen; otherwise the cross is
* drawn on the core copy. Crosses come in only two flavors: BIGCROSS and
* SMALLCROSS.
* Note: This routine is not reentrant; it erases any previous cross
* of the same flavor before displaying the current cross.
* Note 2: For the moment, this routine does nothing unless PICNUM is the
* screen, and FLAVOR is one of BIGCROSS or SMALLCROSS.
*/
cross(xval, yval, w, h, picnum, flavor)
double xval, yval; /* center of new cross to be drawn */
int w; /* have W pixels on either side of center unless we
* hit the sides of the window */
int h; /* have H pixels on top and bottom unless we hit
* the side of the window */
int picnum; /* SCRN for screen; otherwise core copy */
int flavor; /* BIGCROSS or SMALLCROSS */
{
CROSSINFO *c;
POINT *p;
XSegment cseg[2];
int cwidth, cheight; /* of cross to be placed */
int xoff, yoff; /* of upper left corner of imaginary
* box circumscribing the cross */
if((p = FindPixel(xval, yval, picnum)) == NULL
|| flavor != BIGCROSS && flavor != SMALLCROSS)
return;
if(picnum == SCRN) {
c = &scrncross[flavor];
/* Restore previous contents behind existing cross and
* reclaim storage if sizes of crosses have changed
*/
if(c->contents != (Pixmap) 0)
XCopyArea(x_dpy, c->contents, x_window, x_gc,
0, 0, c->width, c->height, c->origin.x, c->origin.y);
xoff = max(p->x - w, 0);
yoff = max(p->y - h, 0);
cwidth = min(scrncols, p->x + w) - xoff + 1;
cheight = min(scrnrows, p->y + h) - yoff + 1;
if(c->contents != (Pixmap) 0 &&
(cwidth != c->width || cheight != c->height)) {
XFreePixmap(x_dpy, c->contents);
c->contents = (Pixmap) 0;
}
if(c->contents == (Pixmap) 0) {
c->contents = XCreatePixmap(x_dpy, x_window, cwidth,
cheight, 1);
c->width = cwidth;
c->height = cheight;
}
c->origin.x = xoff;
c->origin.y = yoff;
/* Save contents of screen in the box which will contain
* the cross and draw the cross on the screen.
*/
XCopyArea(x_dpy, x_window, c->contents, x_gc, xoff, yoff,
cwidth, cheight, 0, 0);
cseg[0].x1 = xoff;
cseg[0].x2 = xoff + cwidth - 1;
cseg[0].y1 = p->y;
cseg[0].y2 = p->y;
cseg[1].x1 = p->x;
cseg[1].x2 = p->x;
cseg[1].y1 = yoff;
cseg[1].y2 = yoff + cheight - 1;
XDrawSegments(x_dpy, x_window, x_gc, &cseg[0], 2);
}
return;
}
/* ------------------------------------------------------------------- */
/* CRTCROSSON - Place a permanent cross on the screen at (x, y)
* containing W pixels on either side of X and H pixels on either side of Y.
* Note: for the moment, COLOR is a dummy argument.
*/
CRTcrossON(xval, yval, m, n, hue)
double xval, yval; /* center of new cross to be drawn */
int m; /* have M pixels on either side of center unless we
* hit the sides of the window */
int n; /* have N pixels on top and bottom unless we hit
* the side of the window */
unsigned hue; /* dummy for now */
{
POINT *p;
XSegment cseg[2];
int xoff, yoff; /* of upper left corner of imaginary
* box circumscribing the cross */
if((p = FindPixel(xval, yval, SCRN)) == NULL)
return;
xoff = max(p->x - m, 0);
yoff = max(p->y - n, 0);
/* Place the cross as a pair of segments */
cseg[0].x1 = xoff;
cseg[0].x2 = min(scrncols, p->x + m) + 1;
cseg[0].y1 = p->y;
cseg[0].y2 = p->y;
cseg[1].x1 = p->x;
cseg[1].x2 = p->x;
cseg[1].y1 = yoff;
cseg[1].y2 = min(scrnrows, p->y + n) + 1;
XDrawSegments(x_dpy, x_window, x_gc, &cseg[0], 2);
return;
}
/* ------------------------------------------------------------------- */
/* TURNOFF - turn off the appropriate cross by restoring the obscured
* area of the screen, if any. Return the storage used to retain the
* obscured area.
*/
turnoff(crossnumber)
int crossnumber;
{
register CROSSINFO *c;
if(crossnumber == BIGCROSS || crossnumber == SMALLCROSS) {
c = &scrncross[crossnumber];
if(c->contents != (Pixmap) 0) {
XCopyArea(x_dpy, c->contents, x_window, x_gc,
0, 0, c->width, c->height, c->origin.x, c->origin.y);
XFreePixmap(x_dpy, c->contents);
c->contents = (Pixmap) 0;
}
if(crossnumber == BIGCROSS)
IsCross0Set = NO;
else
IsCross1Set = NO;
}
return;
}
#endif /* X11 */